//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Dialogue node
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to.
//   Cell 4 - If 1, this creature goes straight to the nav point immediately
//     and never returns

begincreaturescript;

variables;

short i,target;
short health_level = 0;
short last_abil;
short last_zap;
short last_summon;
short is_flee = 0;
short fought_drayk = 0;
short did_split;
short gol_mes = 0;

body;

beginstate INIT_STATE;
	set_boss_level(ME,2);
	set_aggression(ME,8);
	
	health_level = get_max_health(ME);
	
	last_summon = get_current_tick();
	last_abil = get_current_tick();
	last_zap = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(57,11,1);
	
	erase_char(63);
	erase_char(64);
	erase_char(65);
	erase_char(66);
	
	begin_talk_mode(18);
break;

beginstate START_STATE; 
	if ((gf(57,9) > 1) && 
	  (tick_difference(last_zap,get_current_tick()) > 0)) {
		last_zap = get_current_tick();
		damage_char(ME,700,0);
		print_named_str(ME,"is crumbling away.");
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	// hunt pc
	if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 16) && (gf(57,10) > 0)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}
		


	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	
	// drayk business
	if (get_target() == 62)
		fought_drayk = 1;
	if (char_ok(62)) {
		if (can_see_char(62))
			set_foe_target(ME,62);
		}	
		
	
	// crumble
	if ((gf(57,9) > 1) && 
	  (tick_difference(last_zap,get_current_tick()) > 0)) {
		last_zap = get_current_tick();
		damage_char(ME,700,0);
		print_named_str(ME,"is crumbling away.");
		}

	// go heal?
	if ((char_ok(62) == FALSE) && (fought_drayk > 0)) {
		if (get_nearest_party_char(8) >= 0)
			print_str_color("The golem turns and flees.",2);
		is_flee = 1;
		set_state(4);
		}
	if ((gf(57,9) == 0) && (gf(57,10) < 4) && (get_health(ME) < get_max_health(ME) / 2)) {
		if (get_nearest_party_char(8) >= 0)
			print_str_color("The golem turns and flees.",2);
		is_flee = 1;
		set_state(4);
		}
	if (dist_to_nav_point(ME,6) > 20) {
		if (get_nearest_party_char(8) >= 0)
			print_str_color("The golem turns and flees.",2);
		is_flee = 1;
		set_state(4);
		}
		
		
	// spawn critter?
	if ((health_level > get_health(ME)) && (gf(57,9) == 0) && (tick_difference(last_summon,get_current_tick()) > 0)) {
		did_split = 0;
		last_summon = get_current_tick();
		
		
		if (did_split == 0) {
			if (char_ok(get_memory_cell(4)) == FALSE) {
				if (summon_creature(get_memory_cell(4) - 8)) {
					play_sound(174);
					print_str_color("Your blows have knocked loose a bit of your foe. It begins to move.",2);
					set_summon_level(get_memory_cell(4),1);
					set_attack_bonus(get_memory_cell(4),get_memory_cell(8));
					place_particle_num(get_memory_cell(4),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if (did_split == 0) {
			if (char_ok(get_memory_cell(5)) == FALSE) {
				if (summon_creature(get_memory_cell(5) - 8)) {
					play_sound(174);
					print_str_color("Your blows have knocked loose a bit of your foe. It begins to move.",2);
					set_summon_level(get_memory_cell(5),1);
					set_attack_bonus(get_memory_cell(5),get_memory_cell(8));
					place_particle_num(get_memory_cell(5),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if (did_split == 0) {
			if (char_ok(get_memory_cell(6)) == FALSE) {
				if (summon_creature(get_memory_cell(6) - 8)) {
					play_sound(174);
					print_str_color("Your blows have knocked loose a bit of your foe. It begins to move.",2);
					set_summon_level(get_memory_cell(6),1);
					set_attack_bonus(get_memory_cell(6),get_memory_cell(8));
					place_particle_num(get_memory_cell(6),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if (did_split == 0) {
			if (char_ok(get_memory_cell(7)) == FALSE) {
				if (summon_creature(get_memory_cell(7) - 8)) {
					play_sound(174);
					print_str_color("Your blows have knocked loose a bit of your foe. It begins to move.",2);
					set_summon_level(get_memory_cell(7),1);
					set_attack_bonus(get_memory_cell(7),get_memory_cell(8));
					place_particle_num(get_memory_cell(7),1,1,8);
					did_split = 1;
					}
				
				}
			}


		health_level = health_level - 250;
		
		if ((did_split > 0) && (gol_mes == 0)) {
			gol_mes = 1;
			begin_talk_mode(15);
			}
		}

	// daze ae
	if ((is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 3)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();

		  	place_particle_num(ME,4,6,8);
			print_named_str(ME,"emits a low, distracting hum.");
			pc_heard_sound_delay(136,250);						
			status_nearby(40,7,17,0);

		create_text_bubble("Hummmmm ...");

		end();
		}
	
	do_attack();
break;

beginstate 4; // flee
	if (is_flee == 0)
		set_state(START_STATE);
	
	if ((gf(56,25) == 0) && (get_nearest_party_char(8) >= 0)) {
		sf(56,25,1);
		begin_talk_mode(16);
		}
		
	if ((is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();

		  	place_particle_num(ME,4,6,8);
			print_named_str(ME,"emits a loud screech.");
			pc_heard_sound_delay(107,250);						
			status_nearby(50,6,7,0);

		create_text_bubble("Eeeeeeee!");

		end();
		}

	if (dist_to_nav_point(ME,7) <= 2) {
		is_flee = 0;
		fought_drayk = 0;
		
		if (gf(57,8) == 0) {
			heal_char(ME,2000);
			health_level = health_level + 600;
			}
			else if (gf(57,8) == 2)
				damage_char(ME,500,0);
			
		if (get_nearest_party_char(8) >= 0)
			begin_talk_mode(17);
			else print_str_color("You hear a zapping sound coming from nearby.",2);
		}
		else approach_nav_point(ME,7,1);
break;

beginstate TALKING_STATE;
	if (get_memory_cell(0) == 0) {
		print_str("Talking: You make a bit of small talk with this person, but don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(0));
	break;